//
//  ProjectTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/3/8.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "ProjectTableViewCell.h"

@interface ProjectTableViewCell ()

@property(nonatomic,strong)UIView *lineView;

// 任务名字
@property(nonatomic,strong)UILabel *projectTimeLabel;

// 发布任务时间
@property(nonatomic,strong)UILabel *projectNameLabel;

// 编辑
@property(nonatomic,strong)UIButton *editBtn;

// 删除
@property(nonatomic,strong)UIButton *deleteBtn;

@end

@implementation ProjectTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.lineView.hidden=NO;

        self.projectTimeLabel.font=Font_Number(15);

        self.projectNameLabel.font=Font_Number(16);

        self.editBtn.hidden=NO;

        self.deleteBtn.hidden=NO;

        self.backgroundColor=WhiteColor;

    }
    return self;
}

//
-(UIView *)lineView
{
    if (!_lineView) {
        _lineView=[UIView new];
        _lineView.backgroundColor=BGColor;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin));
            make.top.mas_equalTo(0);
        }];
    }
    return _lineView;
}

// projectTimeLabel
- (UILabel *)projectTimeLabel
{
    if (!_projectTimeLabel) {
        _projectTimeLabel=[self getLabelWithText:@"2017年3月4日创建" font:Font_Number(15) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_projectTimeLabel];
        [_projectTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.lineView.mas_bottom).offset(kmargin*3/2);
            make.left.mas_equalTo(kmargin*2);
            make.right.mas_equalTo(-kmargin*2);
        }];
    }
    return _projectTimeLabel;
}

// projectNameLabel
- (UILabel *)projectNameLabel
{
    if (!_projectNameLabel) {
        _projectNameLabel=[self getLabelWithText:@"虚拟办公系统" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_projectNameLabel];
        [_projectNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.projectTimeLabel.mas_bottom).offset(kmargin);
        make.left.mas_equalTo(self.projectTimeLabel.mas_left);
            make.right.mas_equalTo(self.editBtn.mas_left).offset(-kmargin);
        }];
    }
    return _projectNameLabel;
}

// editBtn
-(UIButton *)editBtn
{
    if (!_editBtn) {
    _editBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"EditIcon"] andWithSelectImage:[UIImage imageNamed:@"EditIcon"] andWithBtnAction:^{

            if (self.delegate&&[self.delegate respondsToSelector:@selector(editProjectWithProjectModel:cell:)]) {
                [self.delegate editProjectWithProjectModel:self.projectModel cell:self];
            }
        }];
        [self.contentView addSubview:_editBtn];
//        _editBtn.backgroundColor=MainColor;
        [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.projectNameLabel.mas_centerY);
            make.right.mas_equalTo(self.deleteBtn.mas_left).offset(-kmargin*2.5);
            make.size.mas_equalTo(CGSizeMake(kmargin*2.5,kmargin*2.5));
        }];
    }
    return _editBtn;
}

// deleteBtn
-(UIButton *)deleteBtn
{
    if (!_deleteBtn) {
        _deleteBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"DeleteIcon"] andWithSelectImage:[UIImage imageNamed:@"DeleteIcon"] andWithBtnAction:^{

           if (self.delegate&&[_delegate respondsToSelector:@selector(deleteProjectWithProjectModel:cell:)]) {
                [self.delegate deleteProjectWithProjectModel:self.projectModel cell:self];
            }

        }];
        [self.contentView addSubview:_deleteBtn];
//        _deleteBtn.backgroundColor=MainColor;
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin*2);
            make.left.mas_equalTo(self.editBtn.mas_right).offset(kmargin*2.5);
            make.size.mas_equalTo(CGSizeMake(kmargin*2.5,kmargin*2.5));
            make.centerY.mas_equalTo(self.projectNameLabel.mas_centerY);
        }];
    }
    return _deleteBtn;
}


-(void)setProjectModel:(ProjectModel *)projectModel
{
    _projectModel=projectModel;
    self.projectNameLabel.text=projectModel.project_name;
    self.projectTimeLabel.text=[NSString stringWithFormat:@"%@ 创建",projectModel.in_time];
}

@end
